Skip to content

Mesh::face_arities becomes Option<Vec<u32>> - #80

Open
virtualritz wants to merge 2 commits into
Twinklebear:masterfrom
virtualritz:pr/face-arities
Open

Mesh::face_arities becomes Option<Vec<u32>>#80
virtualritz wants to merge 2 commits into
Twinklebear:masterfrom
virtualritz:pr/face-arities

Conversation

@virtualritz

Copy link
Copy Markdown
Contributor

Summary

Stacks on #79 (progress-callback) — this diff includes both commits until #79 merges; the second commit is the one this PR is actually about.

  • Mesh::face_arities changes from Vec<u32> to Option<Vec<u32>>. None now means "all faces are triangles" instead of an empty Vec, which skips the allocation for triangle-only meshes — the common case, especially with triangulate: true.
  • New Mesh::{face_count, face_arity, is_triangulated, face_indices} helper methods replace manual index-arithmetic over face_arities at call sites (see the updated examples/print_mesh.rs and the crate's module-doc example) — the offset math for finding a given face's indices was previously left to every caller to get right.
  • Also tidies two loops (parse_face, TmpMaterials::extend) into iterator chains while in the area — no behavior change there.

BREAKING CHANGE: any caller reading Mesh::face_arities directly as a Vec needs to match on the Option, or switch to the new helper methods. Happy to gate this behind a semver-major bump on your end, or split differently if you'd rather land it separately from #79 for that reason.

Test plan

  • cargo test --all-features: 21 lib tests + 5 doctests pass, including updated non_triangulated_quad coverage for the None/Some cases
  • cargo build --example print_mesh --all-features
  • cargo fmt --all -- --check: clean
  • cargo clippy --all-targets --all-features -- -D warnings: clean (exit 0)

LoadOptions gains progress_callback: Option<LoadProgressCallback>
(Arc<dyn Fn(&LoadProgress) -> ControlFlow<()> + Send + Sync>, an options
field rather than a second _with_progress function), invoked every 1000
lines during load_obj_buf's parse loop. Returning ControlFlow::Break stops
the load and returns the new LoadError::Cancelled. No behavior change when
progress_callback is None (the default): verified by a test comparing
output with and without a no-op callback. load_obj_buf_async is untouched.
None now means "all faces are triangles" instead of an empty Vec, saving
the allocation for triangle-only meshes -- the common case. New
Mesh::{face_count, face_arity, is_triangulated, face_indices} helpers
replace manual index-arithmetic over face_arities at call sites (see
print_mesh.rs and the module doc example). Also tidies two loops
(parse_face, TmpMaterials::extend) into iterator chains while in the area.

BREAKING CHANGE: any caller reading Mesh::face_arities directly (as a Vec)
needs to match on the Option, or switch to the new helper methods.
@Twinklebear

Copy link
Copy Markdown
Owner

I think bumping the semver to indicate the breaking API change sounds good, I'd put these both out in the same release

@Twinklebear Twinklebear left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding the new convenience methods on the Mesh is useful but we don't need to change the face_arities to an Option, since an empty Vec already doesn't allocate: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.new so it's just an API breaking change w/o much benefit.

@virtualritz

Copy link
Copy Markdown
Contributor Author

It may not allocate but it's just a cleaner API IMHO.
On that note, I am adding parsing for higher order geometry to tobj (will be behind a feature gate>ofc).
Any concerns (it's strictly not so tiny any more, I guess)?
I need to parse Rhino3D and Maya-generated OBJs that contain (trimmed) NURBS.
For people in polygon land: these can easily meshed via truck crate (or my monstertruck fork). I will include an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants